<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Django 1.2 release notes &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../index.html" />
    <link rel="up" title="Release notes" href="index.html" />
    <link rel="next" title="Django 1.1.4 release notes" href="1.1.4.html" />
    <link rel="prev" title="Django 1.2.1 release notes" href="1.2.1.html" />



 
<script type="text/javascript" src="../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="1.2.1.html" title="Django 1.2.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="1.1.4.html" title="Django 1.1.4 release notes">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="releases-1.2">
            
  <div class="section" id="s-django-1-2-release-notes">
<span id="django-1-2-release-notes"></span><h1>Django 1.2 release notes<a class="headerlink" href="#django-1-2-release-notes" title="Permalink to this headline">¶</a></h1>
<p><em>May 17, 2010.</em></p>
<p>Welcome to Django 1.2!</p>
<p>Nearly a year in the making, Django 1.2 packs an impressive list of <a class="reference internal" href="#what-s-new-in-django-1-2">new
features</a> and lots of bug fixes. These release notes cover the new features,
as well as important changes you&#8217;ll want to be aware of when upgrading from
Django 1.1 or older versions.</p>
<div class="section" id="s-overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Django 1.2 introduces several large, important new features, including:</p>
<ul class="simple">
<li>Support for <a class="reference internal" href="#support-for-multiple-databases">multiple database connections</a> in a single Django instance.</li>
<li><a class="reference internal" href="#model-validation">Model validation</a> inspired by Django&#8217;s form validation.</li>
<li>Vastly <a class="reference internal" href="#improved-csrf-protection">improved protection against Cross-Site Request Forgery</a> (CSRF).</li>
<li>A new <a class="reference internal" href="#messages-framework">user &#8220;messages&#8221; framework</a> with support for cookie- and session-based
message for both anonymous and authenticated users.</li>
<li>Hooks for <a class="reference internal" href="#object-level-permissions">object-level permissions</a>, <a class="reference internal" href="#permissions-for-anonymous-users">permissions for anonymous users</a>,
and <a class="reference internal" href="#relaxed-requirements-for-usernames">more flexible username requirements</a>.</li>
<li>Customization of email sending via <a class="reference internal" href="#email-backends">email backends</a>.</li>
<li>New <a class="reference internal" href="#new-in-1-2-smart-if"><em>&#8220;smart&#8221; if template tag</em></a> which supports
comparison operators.</li>
</ul>
<p>These are just the highlights; full details and a complete list of features <a class="reference internal" href="#what-s-new-in-django-1-2">may
be found below</a>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="https://github.com/djangoadvent/djangoadvent-articles">Django Advent</a> covered the release of Django 1.2 with a series of
articles and tutorials that cover some of the new features in depth.</p>
</div>
<p>Wherever possible these features have been introduced in a backwards-compatible
manner per <a class="reference internal" href="../misc/api-stability.html"><em>our API stability policy</em></a> policy.</p>
<p>However, a handful of features <em>have</em> changed in ways that, for some users, will be
backwards-incompatible. The big changes are:</p>
<ul>
<li><p class="first">Support for Python 2.3 has been dropped. See the full notes
below.</p>
</li>
<li><p class="first">The new CSRF protection framework is not backwards-compatible with
the old system. Users of the old system will not be affected until
the old system is removed in Django 1.4.</p>
<p>However, upgrading to the new CSRF protection framework requires a few
important backwards-incompatible changes, detailed in <a class="reference internal" href="#csrf-protection">CSRF Protection</a>,
below.</p>
</li>
<li><p class="first">Authors of custom <a class="reference internal" href="../ref/models/fields.html#django.db.models.Field" title="django.db.models.Field"><tt class="xref py py-class docutils literal"><span class="pre">Field</span></tt></a> subclasses should be
aware that a number of methods have had a change in prototype, detailed
under <a class="reference internal" href="#get-db-prep-methods-on-field">get_db_prep_*() methods on Field</a>, below.</p>
</li>
<li><p class="first">The internals of template tags have changed somewhat; authors of custom
template tags that need to store state (e.g. custom control flow tags)
should ensure that their code follows the new rules for <a class="reference internal" href="#stateful-template-tags">stateful template
tags</a></p>
</li>
<li><p class="first">The <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.decorators.user_passes_test" title="django.contrib.auth.decorators.user_passes_test"><tt class="xref py py-func docutils literal"><span class="pre">user_passes_test()</span></tt></a>,
<a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.decorators.login_required" title="django.contrib.auth.decorators.login_required"><tt class="xref py py-func docutils literal"><span class="pre">login_required()</span></tt></a>, and
<a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.decorators.permission_required" title="django.contrib.auth.decorators.permission_required"><tt class="xref py py-func docutils literal"><span class="pre">permission_required()</span></tt></a>, decorators
from <a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.auth</span></tt></a> only apply to functions and no longer
work on methods. There&#8217;s a simple one-line fix <a class="reference internal" href="#user-passes-test-login-required-and-permission-required">detailed below</a>.</p>
</li>
</ul>
<p>Again, these are just the big features that will affect the most users. Users
upgrading from previous versions of Django are heavily encouraged to consult
the complete list of <a class="reference internal" href="#backwards-incompatible-changes-1-2"><em>backwards-incompatible changes</em></a> and the list of <a class="reference internal" href="#deprecated-features-1-2"><em>deprecated
features</em></a>.</p>
</div>
<div class="section" id="s-python-compatibility">
<span id="python-compatibility"></span><h2>Python compatibility<a class="headerlink" href="#python-compatibility" title="Permalink to this headline">¶</a></h2>
<p>While not a new feature, it&#8217;s important to note that Django 1.2
introduces the first shift in our Python compatibility policy since
Django&#8217;s initial public debut. Previous Django releases were tested
and supported on 2.x Python versions from 2.3 up; Django 1.2, however,
drops official support for Python 2.3. As such, the minimum Python
version required for Django is now 2.4, and Django is tested and
supported on Python 2.4, 2.5 and 2.6, and will be supported on the
as-yet-unreleased Python 2.7.</p>
<p>This change should affect only a small number of Django users, as most
operating-system vendors today are shipping Python 2.4 or newer as
their default version. If you&#8217;re still using Python 2.3, however,
you&#8217;ll need to stick to Django 1.1 until you can upgrade; per
<a class="reference internal" href="../internals/release-process.html"><em>our support policy</em></a>, Django 1.1 will
continue to receive security support until the release of Django 1.3.</p>
<p>A roadmap for Django&#8217;s overall 2.x Python support, and eventual
transition to Python 3.x, is currently being developed, and will be
announced prior to the release of Django 1.3.</p>
</div>
<div class="section" id="s-what-s-new-in-django-1-2">
<span id="what-s-new-in-django-1-2"></span><h2>What&#8217;s new in Django 1.2<a class="headerlink" href="#what-s-new-in-django-1-2" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-support-for-multiple-databases">
<span id="support-for-multiple-databases"></span><h3>Support for multiple databases<a class="headerlink" href="#support-for-multiple-databases" title="Permalink to this headline">¶</a></h3>
<p>Django 1.2 adds the ability to use <a class="reference internal" href="../topics/db/multi-db.html"><em>more than one database</em></a> in your Django project. Queries can be issued at a
specific database with the <tt class="docutils literal"><span class="pre">using()</span></tt> method on <tt class="docutils literal"><span class="pre">QuerySet</span></tt> objects.
Individual objects can be saved to a specific database by providing a <tt class="docutils literal"><span class="pre">using</span></tt>
argument when you call <tt class="docutils literal"><span class="pre">save()</span></tt>.</p>
</div>
<div class="section" id="s-model-validation">
<span id="model-validation"></span><h3>Model validation<a class="headerlink" href="#model-validation" title="Permalink to this headline">¶</a></h3>
<p>Model instances now have support for <a class="reference internal" href="../ref/models/instances.html#validating-objects"><em>validating their own data</em></a>, and both model and form fields now accept configurable
lists of <a class="reference internal" href="../ref/validators.html"><em>validators</em></a> specifying reusable, encapsulated
validation behavior. Note, however, that validation must still be performed
explicitly. Simply invoking a model instance&#8217;s <tt class="docutils literal"><span class="pre">save()</span></tt> method will not
perform any validation of the instance&#8217;s data.</p>
</div>
<div class="section" id="s-improved-csrf-protection">
<span id="improved-csrf-protection"></span><h3>Improved CSRF protection<a class="headerlink" href="#improved-csrf-protection" title="Permalink to this headline">¶</a></h3>
<p>Django now has much improved protection against <a class="reference internal" href="../ref/contrib/csrf.html"><em>Cross-Site Request Forgery
(CSRF) attacks</em></a>. This type of attack occurs when a malicious
Web site contains a link, a form button or some JavaScript that is intended to
perform some action on your Web site, using the credentials of a logged-in user
who visits the malicious site in their browser. A related type of attack, &#8220;login
CSRF,&#8221; where an attacking site tricks a user&#8217;s browser into logging into a site
with someone else&#8217;s credentials, is also covered.</p>
</div>
<div class="section" id="s-messages-framework">
<span id="messages-framework"></span><h3>Messages framework<a class="headerlink" href="#messages-framework" title="Permalink to this headline">¶</a></h3>
<p>Django now includes a robust and configurable <a class="reference internal" href="../ref/contrib/messages.html"><em>messages framework</em></a> with built-in support for cookie- and session-based
messaging, for both anonymous and authenticated clients. The messages framework
replaces the deprecated user message API and allows you to temporarily store
messages in one request and retrieve them for display in a subsequent request
(usually the next one).</p>
</div>
<div class="section" id="s-object-level-permissions">
<span id="object-level-permissions"></span><h3>Object-level permissions<a class="headerlink" href="#object-level-permissions" title="Permalink to this headline">¶</a></h3>
<p>A foundation for specifying permissions at the per-object level has been added.
Although there is no implementation of this in core, a custom authentication
backend can provide this implementation and it will be used by
<a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User" title="django.contrib.auth.models.User"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.auth.models.User</span></tt></a>. See the <a class="reference internal" href="../topics/auth/index.html"><em>authentication docs</em></a> for more information.</p>
</div>
<div class="section" id="s-permissions-for-anonymous-users">
<span id="permissions-for-anonymous-users"></span><h3>Permissions for anonymous users<a class="headerlink" href="#permissions-for-anonymous-users" title="Permalink to this headline">¶</a></h3>
<p>If you provide a custom auth backend with <tt class="docutils literal"><span class="pre">supports_anonymous_user</span></tt> set to
<tt class="docutils literal"><span class="pre">True</span></tt>, AnonymousUser will check the backend for permissions, just like
User already did.  This is useful for centralizing permission handling - apps
can always delegate the question of whether something is allowed or not to
the authorization/authentication backend. See the <a class="reference internal" href="../topics/auth/index.html"><em>authentication
docs</em></a> for more details.</p>
</div>
<div class="section" id="s-relaxed-requirements-for-usernames">
<span id="relaxed-requirements-for-usernames"></span><h3>Relaxed requirements for usernames<a class="headerlink" href="#relaxed-requirements-for-usernames" title="Permalink to this headline">¶</a></h3>
<p>The built-in <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User" title="django.contrib.auth.models.User"><tt class="xref py py-class docutils literal"><span class="pre">User</span></tt></a> model&#8217;s
<a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.username" title="django.contrib.auth.models.User.username"><tt class="xref py py-attr docutils literal"><span class="pre">username</span></tt></a> field now allows a wider range
of characters, including <tt class="docutils literal"><span class="pre">&#64;</span></tt>, <tt class="docutils literal"><span class="pre">+</span></tt>, <tt class="docutils literal"><span class="pre">.</span></tt> and <tt class="docutils literal"><span class="pre">-</span></tt> characters.</p>
</div>
<div class="section" id="s-email-backends">
<span id="email-backends"></span><h3>Email backends<a class="headerlink" href="#email-backends" title="Permalink to this headline">¶</a></h3>
<p>You can now <a class="reference internal" href="../topics/email.html#topic-email-backends"><em>configure the way that Django sends email</em></a>. Instead of using SMTP to send all email, you
can now choose a configurable email backend to send messages. If your
hosting provider uses a sandbox or some other non-SMTP technique for
sending mail, you can now construct an email backend that will allow
Django&#8217;s standard <a class="reference internal" href="../topics/email.html"><em>mail sending methods</em></a> to use
those facilities.</p>
<p>This also makes it easier to debug mail sending. Django ships with
backend implementations that allow you to send email to a
<a class="reference internal" href="../topics/email.html#topic-email-file-backend"><em>file</em></a>, to the
<a class="reference internal" href="../topics/email.html#topic-email-console-backend"><em>console</em></a>, or to
<a class="reference internal" href="../topics/email.html#topic-email-memory-backend"><em>memory</em></a>. You can even configure all
email to be <a class="reference internal" href="../topics/email.html#topic-email-dummy-backend"><em>thrown away</em></a>.</p>
</div>
<div class="section" id="s-smart-if-tag">
<span id="s-new-in-1-2-smart-if"></span><span id="smart-if-tag"></span><span id="new-in-1-2-smart-if"></span><h3>&#8220;Smart&#8221; <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag<a class="headerlink" href="#smart-if-tag" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag has been upgraded to be much more powerful. First, we&#8217;ve
added support for comparison operators. No longer will you have to type:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">ifnotequal</span> <span class="nv">a</span> <span class="nv">b</span> <span class="cp">%}</span>
 ...
<span class="cp">{%</span> <span class="k">endifnotequal</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can now do this:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">if</span> <span class="nv">a</span> <span class="p">!</span><span class="o">=</span> <span class="nv">b</span> <span class="cp">%}</span>
 ...
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>There&#8217;s really no reason to use <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ifequal</span> <span class="pre">%}</span></tt> or <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ifnotequal</span> <span class="pre">%}</span></tt>
anymore, unless you&#8217;re the nostalgic type.</p>
<p>The operators supported are <tt class="docutils literal"><span class="pre">==</span></tt>, <tt class="docutils literal"><span class="pre">!=</span></tt>, <tt class="docutils literal"><span class="pre">&lt;</span></tt>, <tt class="docutils literal"><span class="pre">&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;=</span></tt>, <tt class="docutils literal"><span class="pre">&gt;=</span></tt>,
<tt class="docutils literal"><span class="pre">in</span></tt> and <tt class="docutils literal"><span class="pre">not</span> <span class="pre">in</span></tt>, all of which work like the Python operators, in addition
to <tt class="docutils literal"><span class="pre">and</span></tt>, <tt class="docutils literal"><span class="pre">or</span></tt> and <tt class="docutils literal"><span class="pre">not</span></tt>, which were already supported.</p>
<p>Also, filters may now be used in the <tt class="docutils literal"><span class="pre">if</span></tt> expression. For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;div</span>
  <span class="cp">{%</span> <span class="k">if</span> <span class="nv">user.email</span><span class="o">|</span><span class="nf">lower</span> <span class="o">==</span> <span class="nv">message.recipient</span><span class="o">|</span><span class="nf">lower</span> <span class="cp">%}</span>
    <span class="na">class=</span><span class="s">&quot;highlight&quot;</span>
  <span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="nt">&gt;</span><span class="cp">{{</span> <span class="nv">message</span> <span class="cp">}}</span><span class="nt">&lt;/div&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-template-caching">
<span id="template-caching"></span><h3>Template caching<a class="headerlink" href="#template-caching" title="Permalink to this headline">¶</a></h3>
<p>In previous versions of Django, every time you rendered a template, it
would be reloaded from disk. In Django 1.2, you can use a <a class="reference internal" href="../ref/templates/api.html#template-loaders"><em>cached
template loader</em></a> to load templates once, then
cache the result for every subsequent render. This can lead to a
significant performance improvement if your templates are broken into
lots of smaller subtemplates (using the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">%}</span></tt> or <tt class="docutils literal"><span class="pre">{%</span>
<span class="pre">include</span> <span class="pre">%}</span></tt> tags).</p>
<p>As a side effect, it is now much easier to support non-Django template
languages. For more details, see the <a class="reference internal" href="../ref/templates/api.html#topic-template-alternate-language"><em>notes on supporting
non-Django template languages</em></a>.</p>
</div>
<div class="section" id="s-class-based-template-loaders">
<span id="class-based-template-loaders"></span><h3>Class-based template loaders<a class="headerlink" href="#class-based-template-loaders" title="Permalink to this headline">¶</a></h3>
<p>As part of the changes made to introduce <a class="reference internal" href="#template-caching">Template caching</a>  and following
a general trend in Django, the template loaders API has been modified
to use template loading mechanisms that are encapsulated in Python classes as
opposed to functions, the only method available until Django 1.1.</p>
<p>All the template loaders <a class="reference internal" href="../ref/templates/api.html#template-loaders"><em>shipped with Django</em></a> have
been ported to the new API but they still implement the function-based API and
the template core machinery still accepts function-based loaders (builtin or
third party) so there is no immediate need to modify your
<a class="reference internal" href="../ref/settings.html#std:setting-TEMPLATE_LOADERS"><tt class="xref std std-setting docutils literal"><span class="pre">TEMPLATE_LOADERS</span></tt></a> setting in existing projects, things will keep
working if you leave it untouched up to and including the Django 1.3 release.</p>
<p>If you have developed your own custom template loaders we suggest to consider
porting them to a class-based implementation because the code for backwards
compatibility with function-based loaders starts its deprecation process in
Django 1.2 and will be removed in Django 1.4.  There is a description of the
API these loader classes must implement <a class="reference internal" href="../ref/templates/api.html#topic-template-alternate-language"><em>here</em></a> and you can also examine the source code
of the loaders shipped with Django.</p>
</div>
<div class="section" id="s-natural-keys-in-fixtures">
<span id="natural-keys-in-fixtures"></span><h3>Natural keys in fixtures<a class="headerlink" href="#natural-keys-in-fixtures" title="Permalink to this headline">¶</a></h3>
<p>Fixtures can now refer to remote objects using
<a class="reference internal" href="../topics/serialization.html#topics-serialization-natural-keys"><em>Natural keys</em></a>. This lookup scheme is an
alternative to the normal primary-key based object references in a
fixture, improving readability and resolving problems referring to
objects whose primary key value may not be predictable or known.</p>
</div>
<div class="section" id="s-fast-failure-for-tests">
<span id="fast-failure-for-tests"></span><h3>Fast failure for tests<a class="headerlink" href="#fast-failure-for-tests" title="Permalink to this headline">¶</a></h3>
<p>Both the <a class="reference internal" href="../ref/django-admin.html#django-admin-test"><tt class="xref std std-djadmin docutils literal"><span class="pre">test</span></tt></a> subcommand of <tt class="docutils literal"><span class="pre">django-admin.py</span></tt> and the
<tt class="docutils literal"><span class="pre">runtests.py</span></tt> script used to run Django&#8217;s own test suite now support a
<tt class="docutils literal"><span class="pre">--failfast</span></tt> option. When specified, this option causes the test runner to
exit after encountering a failure instead of continuing with the test run. In
addition, the handling of <tt class="docutils literal"><span class="pre">Ctrl-C</span></tt> during a test run has been improved to
trigger a graceful exit from the test run that reports details of the tests that
were run before the interruption.</p>
</div>
<div class="section" id="s-bigintegerfield">
<span id="bigintegerfield"></span><h3><tt class="docutils literal"><span class="pre">BigIntegerField</span></tt><a class="headerlink" href="#bigintegerfield" title="Permalink to this headline">¶</a></h3>
<p>Models can now use a 64-bit <a class="reference internal" href="../ref/models/fields.html#django.db.models.BigIntegerField" title="django.db.models.BigIntegerField"><tt class="xref py py-class docutils literal"><span class="pre">BigIntegerField</span></tt></a> type.</p>
</div>
<div class="section" id="s-improved-localization">
<span id="improved-localization"></span><h3>Improved localization<a class="headerlink" href="#improved-localization" title="Permalink to this headline">¶</a></h3>
<p>Django&#8217;s <a class="reference internal" href="../topics/i18n/index.html"><em>internationalization framework</em></a> has been expanded
with locale-aware formatting and form processing. That means, if enabled, dates
and numbers on templates will be displayed using the format specified for the
current locale. Django will also use localized formats when parsing data in
forms. See <a class="reference internal" href="../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a> for more details.</p>
</div>
<div class="section" id="s-readonly-fields-in-modeladmin">
<span id="readonly-fields-in-modeladmin"></span><h3><tt class="docutils literal"><span class="pre">readonly_fields</span></tt> in <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt><a class="headerlink" href="#readonly-fields-in-modeladmin" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">django.contrib.admin.ModelAdmin.readonly_fields</span></tt></a> has been added to
enable non-editable fields in add/change pages for models and inlines. Field
and calculated values can be displayed alongside editable fields.</p>
</div>
<div class="section" id="s-customizable-syntax-highlighting">
<span id="customizable-syntax-highlighting"></span><h3>Customizable syntax highlighting<a class="headerlink" href="#customizable-syntax-highlighting" title="Permalink to this headline">¶</a></h3>
<p>You can now use a <tt class="docutils literal"><span class="pre">DJANGO_COLORS</span></tt> environment variable to modify or disable
the colors used by <tt class="docutils literal"><span class="pre">django-admin.py</span></tt> to provide <a class="reference internal" href="../ref/django-admin.html#syntax-coloring"><em>syntax highlighting</em></a>.</p>
</div>
<div class="section" id="s-syndication-feeds-as-views">
<span id="syndication-feeds-as-views"></span><h3>Syndication feeds as views<a class="headerlink" href="#syndication-feeds-as-views" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="../ref/contrib/syndication.html"><em>Syndication feeds</em></a> can now be used directly as
views in your <a class="reference internal" href="../topics/http/urls.html"><em>URLconf</em></a>. This means that you can
maintain complete control over the URL structure of your feeds. Like any other
view, feeds views are passed a <tt class="docutils literal"><span class="pre">request</span></tt> object, so you can do anything you
would normally do with a view, like user based access control, or making a feed
a named URL.</p>
</div>
<div class="section" id="s-geodjango">
<span id="geodjango"></span><h3>GeoDjango<a class="headerlink" href="#geodjango" title="Permalink to this headline">¶</a></h3>
<p>The most significant new feature for <a class="reference internal" href="../ref/contrib/gis/index.html"><em>GeoDjango</em></a>
in 1.2 is support for multiple spatial databases.  As a result,
the following <a class="reference internal" href="../ref/contrib/gis/db-api.html#spatial-backends"><em>spatial database backends</em></a>
are now included:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">django.contrib.gis.db.backends.postgis</span></tt></li>
<li><tt class="docutils literal"><span class="pre">django.contrib.gis.db.backends.mysql</span></tt></li>
<li><tt class="docutils literal"><span class="pre">django.contrib.gis.db.backends.oracle</span></tt></li>
<li><tt class="docutils literal"><span class="pre">django.contrib.gis.db.backends.spatialite</span></tt></li>
</ul>
<p>GeoDjango now supports the rich capabilities added
in the <a class="reference external" href="http://postgis.refractions.net/documentation/manual-1.5/">PostGIS 1.5 release</a>.
New features include support for the <a class="reference internal" href="../ref/contrib/gis/model-api.html#geography-type"><em>geography type</em></a>
and enabling of <a class="reference internal" href="../ref/contrib/gis/db-api.html#distance-queries"><em>distance queries</em></a>
with non-point geometries on geographic coordinate systems.</p>
<p>Support for 3D geometry fields was added, and may be enabled
by setting the <a class="reference internal" href="../ref/contrib/gis/model-api.html#django.contrib.gis.db.models.GeometryField.dim" title="django.contrib.gis.db.models.GeometryField.dim"><tt class="xref py py-attr docutils literal"><span class="pre">dim</span></tt></a>
keyword to 3 in your <a class="reference internal" href="../ref/contrib/gis/model-api.html#django.contrib.gis.db.models.GeometryField" title="django.contrib.gis.db.models.GeometryField"><tt class="xref py py-class docutils literal"><span class="pre">GeometryField</span></tt></a>.
The <a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.Extent3D" title="django.contrib.gis.db.models.Extent3D"><tt class="xref py py-class docutils literal"><span class="pre">Extent3D</span></tt></a> aggregate
and <a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.GeoQuerySet.extent3d" title="django.contrib.gis.db.models.GeoQuerySet.extent3d"><tt class="xref py py-meth docutils literal"><span class="pre">extent3d()</span></tt></a> <tt class="docutils literal"><span class="pre">GeoQuerySet</span></tt>
method were added as a part of this feature.</p>
<p>The following <a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.GeoQuerySet" title="django.contrib.gis.db.models.GeoQuerySet"><tt class="xref py py-class docutils literal"><span class="pre">GeoQuerySet</span></tt></a>
methods are new in 1.2:</p>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.GeoQuerySet.force_rhr" title="django.contrib.gis.db.models.GeoQuerySet.force_rhr"><tt class="xref py py-meth docutils literal"><span class="pre">force_rhr()</span></tt></a></li>
<li><a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.GeoQuerySet.reverse_geom" title="django.contrib.gis.db.models.GeoQuerySet.reverse_geom"><tt class="xref py py-meth docutils literal"><span class="pre">reverse_geom()</span></tt></a></li>
<li><a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#django.contrib.gis.db.models.GeoQuerySet.geohash" title="django.contrib.gis.db.models.GeoQuerySet.geohash"><tt class="xref py py-meth docutils literal"><span class="pre">geohash()</span></tt></a></li>
</ul>
<p>The <a class="reference internal" href="../ref/contrib/gis/geos.html#ref-geos"><em>GEOS interface</em></a> was updated to use
thread-safe C library functions when available on the platform.</p>
<p>The <a class="reference internal" href="../ref/contrib/gis/gdal.html#ref-gdal"><em>GDAL interface</em></a> now allows the user to
set a <a class="reference internal" href="../ref/contrib/gis/gdal.html#django.contrib.gis.gdal.Layer.spatial_filter" title="django.contrib.gis.gdal.Layer.spatial_filter"><tt class="xref py py-attr docutils literal"><span class="pre">spatial_filter</span></tt></a> on
the features returned when iterating over a
<a class="reference internal" href="../ref/contrib/gis/gdal.html#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><tt class="xref py py-class docutils literal"><span class="pre">Layer</span></tt></a>.</p>
<p>Finally, <a class="reference internal" href="../ref/contrib/gis/index.html"><em>GeoDjango&#8217;s documentation</em></a> is now
included with Django&#8217;s and is no longer
hosted separately at <a class="reference external" href="http://geodjango.org/">geodjango.org</a>.</p>
</div>
<div class="section" id="s-javascript-assisted-handling-of-inline-related-objects-in-the-admin">
<span id="s-js-assisted-inlines"></span><span id="javascript-assisted-handling-of-inline-related-objects-in-the-admin"></span><span id="js-assisted-inlines"></span><h3>JavaScript-assisted handling of inline related objects in the admin<a class="headerlink" href="#javascript-assisted-handling-of-inline-related-objects-in-the-admin" title="Permalink to this headline">¶</a></h3>
<p>If a user has JavaScript enabled in their browser, the interface for
inline objects in the admin now allows inline objects to be
dynamically added and removed. Users without JavaScript-enabled
browsers will see no change in the behavior of inline objects.</p>
</div>
<div class="section" id="s-new-now-template-tag-format-specifier-characters-c-and-u">
<span id="new-now-template-tag-format-specifier-characters-c-and-u"></span><h3>New <tt class="docutils literal"><span class="pre">now</span></tt> template tag format specifier characters: <tt class="docutils literal"><span class="pre">c</span></tt> and <tt class="docutils literal"><span class="pre">u</span></tt><a class="headerlink" href="#new-now-template-tag-format-specifier-characters-c-and-u" title="Permalink to this headline">¶</a></h3>
<p>The argument to the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-now"><tt class="xref std std-ttag docutils literal"><span class="pre">now</span></tt></a> has gained two new format characters:
<tt class="docutils literal"><span class="pre">c</span></tt> to specify that a datetime value should be formatted in ISO 8601
format, and <tt class="docutils literal"><span class="pre">u</span></tt> that allows output of the microseconds part of a
datetime or time value.</p>
<p>These are also available in others parts like the <a class="reference internal" href="../ref/templates/builtins.html#std:templatefilter-date"><tt class="xref std std-tfilter docutils literal"><span class="pre">date</span></tt></a> and
<a class="reference internal" href="../ref/templates/builtins.html#std:templatefilter-time"><tt class="xref std std-tfilter docutils literal"><span class="pre">time</span></tt></a> template filters, the <tt class="docutils literal"><span class="pre">humanize</span></tt> template tag library
and the new <a class="reference internal" href="#improved-localization">format localization</a> framework.</p>
</div>
</div>
<div class="section" id="s-backwards-incompatible-changes-in-1-2">
<span id="s-backwards-incompatible-changes-1-2"></span><span id="backwards-incompatible-changes-in-1-2"></span><span id="backwards-incompatible-changes-1-2"></span><h2>Backwards-incompatible changes in 1.2<a class="headerlink" href="#backwards-incompatible-changes-in-1-2" title="Permalink to this headline">¶</a></h2>
<p>Wherever possible the new features above have been introduced in a
backwards-compatible manner per <a class="reference internal" href="../misc/api-stability.html"><em>our API stability policy</em></a> policy. This means that practically all existing
code which worked with Django 1.1 will continue to work with Django
1.2; such code will, however, begin issuing warnings (see below for
details).</p>
<p>However, a handful of features <em>have</em> changed in ways that, for some
users, will be immediately backwards-incompatible. Those changes are
detailed below.</p>
<div class="section" id="s-csrf-protection">
<span id="csrf-protection"></span><h3>CSRF Protection<a class="headerlink" href="#csrf-protection" title="Permalink to this headline">¶</a></h3>
<p>We&#8217;ve made large changes to the way CSRF protection works, detailed in
<a class="reference internal" href="../ref/contrib/csrf.html"><em>the CSRF documentation</em></a>. Here are the major changes you
should be aware of:</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">CsrfResponseMiddleware</span></tt> and <tt class="docutils literal"><span class="pre">CsrfMiddleware</span></tt> have been deprecated and
will be removed completely in Django 1.4, in favor of a template tag that
should be inserted into forms.</p>
</li>
<li><p class="first">All contrib apps use a <tt class="docutils literal"><span class="pre">csrf_protect</span></tt> decorator to protect the view. This
requires the use of the <tt class="docutils literal"><span class="pre">csrf_token</span></tt> template tag in the template. If you
have used custom templates for contrib views, you MUST READ THE UPGRADE
INSTRUCTIONS to fix those templates.</p>
<div class="admonition-documentation-removed admonition">
<p class="first admonition-title">Documentation removed</p>
<p class="last">The upgrade notes have been removed in current Django docs. Please refer
to the docs for Django 1.3 or older to find these instructions.</p>
</div>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">CsrfViewMiddleware</span></tt> is included in <a class="reference internal" href="../ref/settings.html#std:setting-MIDDLEWARE_CLASSES"><tt class="xref std std-setting docutils literal"><span class="pre">MIDDLEWARE_CLASSES</span></tt></a> by
default. This turns on CSRF protection by default, so views that accept
POST requests need to be written to work with the middleware. Instructions
on how to do this are found in the CSRF docs.</p>
</li>
<li><p class="first">All of the CSRF has moved from contrib to core (with backwards
compatible imports in the old locations, which are deprecated and
will cease to be supported in Django 1.4).</p>
</li>
</ul>
</div>
<div class="section" id="s-get-db-prep-methods-on-field">
<span id="get-db-prep-methods-on-field"></span><h3><tt class="docutils literal"><span class="pre">get_db_prep_*()</span></tt> methods on <tt class="docutils literal"><span class="pre">Field</span></tt><a class="headerlink" href="#get-db-prep-methods-on-field" title="Permalink to this headline">¶</a></h3>
<p>Prior to Django 1.2, a custom <tt class="docutils literal"><span class="pre">Field</span></tt> had the option of defining
several functions to support conversion of Python values into
database-compatible values. A custom field might look something like:</p>
<div class="highlight-python"><div class="highlight"><pre>class CustomModelField(models.Field):
    # ...
    def db_type(self):
        # ...

    def get_db_prep_save(self, value):
        # ...

    def get_db_prep_value(self, value):
        # ...

    def get_db_prep_lookup(self, lookup_type, value):
        # ...
</pre></div>
</div>
<p>In 1.2, these three methods have undergone a change in prototype, and
two extra methods have been introduced:</p>
<div class="highlight-python"><div class="highlight"><pre>class CustomModelField(models.Field):
    # ...

    def db_type(self, connection):
        # ...

    def get_prep_value(self, value):
        # ...

    def get_prep_lookup(self, lookup_type, value):
        # ...

    def get_db_prep_save(self, value, connection):
        # ...

    def get_db_prep_value(self, value, connection, prepared=False):
        # ...

    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
        # ...
</pre></div>
</div>
<p>These changes are required to support multiple databases &#8211;
<tt class="docutils literal"><span class="pre">db_type</span></tt> and <tt class="docutils literal"><span class="pre">get_db_prep_*</span></tt> can no longer make any assumptions
regarding the database for which it is preparing. The <tt class="docutils literal"><span class="pre">connection</span></tt>
argument now provides the preparation methods with the specific
connection for which the value is being prepared.</p>
<p>The two new methods exist to differentiate general data-preparation
requirements from requirements that are database-specific. The
<tt class="docutils literal"><span class="pre">prepared</span></tt> argument is used to indicate to the database-preparation
methods whether generic value preparation has been performed. If
an unprepared (i.e., <tt class="docutils literal"><span class="pre">prepared=False</span></tt>) value is provided to the
<tt class="docutils literal"><span class="pre">get_db_prep_*()</span></tt> calls, they should invoke the corresponding
<tt class="docutils literal"><span class="pre">get_prep_*()</span></tt> calls to perform generic data preparation.</p>
<p>We&#8217;ve provided conversion functions that will transparently
convert functions adhering to the old prototype into functions
compatible with the new prototype. However, these conversion functions
will be removed in Django 1.4, so you should upgrade your <tt class="docutils literal"><span class="pre">Field</span></tt>
definitions to use the new prototype as soon as possible.</p>
<p>If your <tt class="docutils literal"><span class="pre">get_db_prep_*()</span></tt> methods made no use of the database
connection, you should be able to upgrade by renaming
<tt class="docutils literal"><span class="pre">get_db_prep_value()</span></tt> to <tt class="docutils literal"><span class="pre">get_prep_value()</span></tt> and
<tt class="docutils literal"><span class="pre">get_db_prep_lookup()</span></tt> to <tt class="docutils literal"><span class="pre">get_prep_lookup()</span></tt>. If you require
database specific conversions, then you will need to provide an
implementation <tt class="docutils literal"><span class="pre">get_db_prep_*</span></tt> that uses the <tt class="docutils literal"><span class="pre">connection</span></tt>
argument to resolve database-specific values.</p>
</div>
<div class="section" id="s-stateful-template-tags">
<span id="stateful-template-tags"></span><h3>Stateful template tags<a class="headerlink" href="#stateful-template-tags" title="Permalink to this headline">¶</a></h3>
<p>Template tags that store rendering state on their <tt class="docutils literal"><span class="pre">Node</span></tt> subclass
have always been vulnerable to thread-safety and other issues; as of
Django 1.2, however, they may also cause problems when used with the
new <a class="reference internal" href="../ref/templates/api.html#template-loaders"><em>cached template loader</em></a>.</p>
<p>All of the built-in Django template tags are safe to use with the cached
loader, but if you&#8217;re using custom template tags that come from third
party packages, or from your own code, you should ensure that the
<tt class="docutils literal"><span class="pre">Node</span></tt> implementation for each tag is thread-safe. For more
information, see
<a class="reference internal" href="../howto/custom-template-tags.html#template-tag-thread-safety"><em>template tag thread safety considerations</em></a>.</p>
<p>You may also need to update your templates if you were relying on the
implementation of Django&#8217;s template tags <em>not</em> being thread safe. The
<a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-cycle"><tt class="xref std std-ttag docutils literal"><span class="pre">cycle</span></tt></a> tag is the most likely to be affected in this way,
especially when used in conjunction with the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">include</span></tt></a> tag.
Consider the following template fragment:</p>
<div class="highlight-python"><div class="highlight"><pre>{% for object in object_list %}
    {% include &quot;subtemplate.html&quot; %}
{% endfor %}
</pre></div>
</div>
<p>with a <tt class="docutils literal"><span class="pre">subtemplate.html</span></tt> that reads:</p>
<div class="highlight-python"><div class="highlight"><pre>{% cycle &#39;even&#39; &#39;odd&#39; %}
</pre></div>
</div>
<p>Using the non-thread-safe, pre-Django 1.2 renderer, this would output:</p>
<div class="highlight-python"><div class="highlight"><pre>even odd even odd ...
</pre></div>
</div>
<p>Using the thread-safe Django 1.2 renderer, you will instead get:</p>
<div class="highlight-python"><div class="highlight"><pre>even even even even ...
</pre></div>
</div>
<p>This is because each rendering of the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">include</span></tt></a> tag is an
independent rendering. When the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-cycle"><tt class="xref std std-ttag docutils literal"><span class="pre">cycle</span></tt></a> tag was not thread safe,
the state of the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-cycle"><tt class="xref std std-ttag docutils literal"><span class="pre">cycle</span></tt></a> tag would leak between multiple
renderings of the same <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">include</span></tt></a>. Now that the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-cycle"><tt class="xref std std-ttag docutils literal"><span class="pre">cycle</span></tt></a> tag
is thread safe, this leakage no longer occurs.</p>
</div>
<div class="section" id="s-user-passes-test-login-required-and-permission-required">
<span id="user-passes-test-login-required-and-permission-required"></span><h3><tt class="docutils literal"><span class="pre">user_passes_test</span></tt>, <tt class="docutils literal"><span class="pre">login_required</span></tt> and <tt class="docutils literal"><span class="pre">permission_required</span></tt><a class="headerlink" href="#user-passes-test-login-required-and-permission-required" title="Permalink to this headline">¶</a></h3>
<p><tt class="docutils literal"><span class="pre">django.contrib.auth.decorators</span></tt> provides the decorators
<tt class="docutils literal"><span class="pre">login_required</span></tt>, <tt class="docutils literal"><span class="pre">permission_required</span></tt> and
<tt class="docutils literal"><span class="pre">user_passes_test</span></tt>. Previously it was possible to use these
decorators both on functions (where the first argument is &#8216;request&#8217;)
and on methods (where the first argument is &#8216;self&#8217;, and the second
argument is &#8216;request&#8217;). Unfortunately, flaws were discovered in the
code supporting this: it only works in limited circumstances, and
produces errors that are very difficult to debug when it does not
work.</p>
<p>For this reason, the &#8216;auto adapt&#8217; behavior has been removed, and if
you are using these decorators on methods, you will need to manually
apply <a class="reference internal" href="../ref/utils.html#django.utils.decorators.method_decorator" title="django.utils.decorators.method_decorator"><tt class="xref py py-func docutils literal"><span class="pre">django.utils.decorators.method_decorator()</span></tt></a> to convert the
decorator to one that works with methods. For example, you would
change code from this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="nd">@login_required</span>
    <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>to this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils.decorators</span> <span class="kn">import</span> <span class="n">method_decorator</span>

<span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="nd">@method_decorator</span><span class="p">(</span><span class="n">login_required</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils.decorators</span> <span class="kn">import</span> <span class="n">method_decorator</span>

<span class="n">login_required_m</span> <span class="o">=</span> <span class="n">method_decorator</span><span class="p">(</span><span class="n">login_required</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="nd">@login_required_m</span>
    <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>For those of you who&#8217;ve been following the development trunk, this
change also applies to other decorators introduced since 1.1,
including <tt class="docutils literal"><span class="pre">csrf_protect</span></tt>, <tt class="docutils literal"><span class="pre">cache_control</span></tt> and anything created
using <tt class="docutils literal"><span class="pre">decorator_from_middleware</span></tt>.</p>
</div>
<div class="section" id="s-if-tag-changes">
<span id="if-tag-changes"></span><h3><a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag changes<a class="headerlink" href="#if-tag-changes" title="Permalink to this headline">¶</a></h3>
<p>Due to new features in the <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> template tag, it no longer
accepts &#8216;and&#8217;, &#8216;or&#8217; and &#8216;not&#8217; as valid <strong>variable</strong> names. Previously,
these strings could be used as variable names. Now, the keyword status
is always enforced, and template code such as <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">not</span> <span class="pre">%}</span></tt> or <tt class="docutils literal"><span class="pre">{%</span>
<span class="pre">if</span> <span class="pre">and</span> <span class="pre">%}</span></tt> will throw a <tt class="docutils literal"><span class="pre">TemplateSyntaxError</span></tt>. Also, <tt class="docutils literal"><span class="pre">in</span></tt> is a
new keyword and so is not a valid variable name in this tag.</p>
</div>
<div class="section" id="s-lazyobject">
<span id="lazyobject"></span><h3><tt class="docutils literal"><span class="pre">LazyObject</span></tt><a class="headerlink" href="#lazyobject" title="Permalink to this headline">¶</a></h3>
<p><tt class="docutils literal"><span class="pre">LazyObject</span></tt> is an undocumented-but-often-used utility class used for lazily
wrapping other objects of unknown type.</p>
<p>In Django 1.1 and earlier, it handled introspection in a non-standard way,
depending on wrapped objects implementing a public method named
<tt class="docutils literal"><span class="pre">get_all_members()</span></tt>. Since this could easily lead to name clashes, it has been
changed to use the standard Python introspection method, involving
<tt class="docutils literal"><span class="pre">__members__</span></tt> and <tt class="docutils literal"><span class="pre">__dir__()</span></tt>.</p>
<p>If you used <tt class="docutils literal"><span class="pre">LazyObject</span></tt> in your own code
and implemented the <tt class="docutils literal"><span class="pre">get_all_members()</span></tt> method for wrapped objects, you&#8217;ll need
to make a couple of changes:</p>
<p>First, if your class does not have special requirements for introspection (i.e.,
you have not implemented <tt class="docutils literal"><span class="pre">__getattr__()</span></tt> or other methods that allow for
attributes not discoverable by normal mechanisms), you can simply remove the
<tt class="docutils literal"><span class="pre">get_all_members()</span></tt> method. The default implementation on <tt class="docutils literal"><span class="pre">LazyObject</span></tt> will
do the right thing.</p>
<p>If you have more complex requirements for introspection, first rename the
<tt class="docutils literal"><span class="pre">get_all_members()</span></tt> method to <tt class="docutils literal"><span class="pre">__dir__()</span></tt>. This is the standard
introspection method for Python 2.6 and above. If you require support for Python
versions earlier than 2.6, add the following code to the class:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">__members__</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dir__</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="section" id="s-dict-on-model-instances">
<span id="dict-on-model-instances"></span><h3><tt class="docutils literal"><span class="pre">__dict__</span></tt> on model instances<a class="headerlink" href="#dict-on-model-instances" title="Permalink to this headline">¶</a></h3>
<p>Historically, the <tt class="docutils literal"><span class="pre">__dict__</span></tt> attribute of a model instance has only contained
attributes corresponding to the fields on a model.</p>
<p>In order to support multiple database configurations, Django 1.2 has
added a <tt class="docutils literal"><span class="pre">_state</span></tt> attribute to object instances. This attribute will
appear in <tt class="docutils literal"><span class="pre">__dict__</span></tt> for a model instance. If your code relies on
iterating over <tt class="docutils literal"><span class="pre">__dict__</span></tt> to obtain a list of fields, you must now
be prepared to handle or filter out the <tt class="docutils literal"><span class="pre">_state</span></tt> attribute.</p>
</div>
<div class="section" id="s-test-runner-exit-status-code">
<span id="test-runner-exit-status-code"></span><h3>Test runner exit status code<a class="headerlink" href="#test-runner-exit-status-code" title="Permalink to this headline">¶</a></h3>
<p>The exit status code of the test runners (<tt class="docutils literal"><span class="pre">tests/runtests.py</span></tt> and <tt class="docutils literal"><span class="pre">python</span>
<span class="pre">manage.py</span> <span class="pre">test</span></tt>) no longer represents the number of failed tests, because a
failure of 256 or more tests resulted in a wrong exit status code. The exit
status code for the test runner is now 0 for success (no failing tests) and 1
for any number of test failures. If needed, the number of test failures can be
found at the end of the test runner&#8217;s output.</p>
</div>
<div class="section" id="s-cookie-encoding">
<span id="cookie-encoding"></span><h3>Cookie encoding<a class="headerlink" href="#cookie-encoding" title="Permalink to this headline">¶</a></h3>
<p>To fix bugs with cookies in Internet Explorer, Safari, and possibly
other browsers, our encoding of cookie values was changed so that the
comma and semicolon are treated as non-safe characters, and are
therefore encoded as <tt class="docutils literal"><span class="pre">\054</span></tt> and <tt class="docutils literal"><span class="pre">\073</span></tt> respectively.  This could
produce backwards incompatibilities, especially if you are storing
comma or semi-colon in cookies and have javascript code that parses
and manipulates cookie values client-side.</p>
</div>
<div class="section" id="s-modelform-is-valid-and-modelform-errors">
<span id="modelform-is-valid-and-modelform-errors"></span><h3><tt class="docutils literal"><span class="pre">ModelForm.is_valid()</span></tt> and <tt class="docutils literal"><span class="pre">ModelForm.errors</span></tt><a class="headerlink" href="#modelform-is-valid-and-modelform-errors" title="Permalink to this headline">¶</a></h3>
<p>Much of the validation work for ModelForms has been moved down to the model
level. As a result, the first time you call <tt class="docutils literal"><span class="pre">ModelForm.is_valid()</span></tt>, access
<tt class="docutils literal"><span class="pre">ModelForm.errors</span></tt> or otherwise trigger form validation, your model will be
cleaned in-place. This conversion used to happen when the model was saved. If
you need an unmodified instance of your model, you should pass a copy to the
<tt class="docutils literal"><span class="pre">ModelForm</span></tt> constructor.</p>
</div>
<div class="section" id="s-booleanfield-on-mysql">
<span id="booleanfield-on-mysql"></span><h3><tt class="docutils literal"><span class="pre">BooleanField</span></tt> on MySQL<a class="headerlink" href="#booleanfield-on-mysql" title="Permalink to this headline">¶</a></h3>
<p>In previous versions of Django, a model&#8217;s <tt class="docutils literal"><span class="pre">BooleanField</span></tt> under MySQL
would return its value as either <tt class="docutils literal"><span class="pre">1</span></tt> or <tt class="docutils literal"><span class="pre">0</span></tt>, instead of <tt class="docutils literal"><span class="pre">True</span></tt>
or <tt class="docutils literal"><span class="pre">False</span></tt>; for most people this wasn&#8217;t a problem because <tt class="docutils literal"><span class="pre">bool</span></tt>
is a subclass of <tt class="docutils literal"><span class="pre">int</span></tt> in Python. In Django 1.2, however,
<tt class="docutils literal"><span class="pre">BooleanField</span></tt> on MySQL correctly returns a real <tt class="docutils literal"><span class="pre">bool</span></tt>.  The only
time this should ever be an issue is if you were expecting the
<tt class="docutils literal"><span class="pre">repr</span></tt> of a <tt class="docutils literal"><span class="pre">BooleanField</span></tt> to print <tt class="docutils literal"><span class="pre">1</span></tt> or <tt class="docutils literal"><span class="pre">0</span></tt>.</p>
</div>
<div class="section" id="s-changes-to-the-interpretation-of-max-num-in-formsets">
<span id="changes-to-the-interpretation-of-max-num-in-formsets"></span><h3>Changes to the interpretation of <tt class="docutils literal"><span class="pre">max_num</span></tt> in FormSets<a class="headerlink" href="#changes-to-the-interpretation-of-max-num-in-formsets" title="Permalink to this headline">¶</a></h3>
<p>As part of enhancements made to the handling of FormSets, the default
value and interpretation of the <tt class="docutils literal"><span class="pre">max_num</span></tt> parameter to the
<a class="reference internal" href="../topics/forms/formsets.html#formsets-max-num"><em>django.forms.formsets.formset_factory()</em></a> and
<a class="reference internal" href="../topics/forms/modelforms.html#model-formsets-max-num"><em>django.forms.models.modelformset_factory()</em></a> functions has changed slightly. This
change also affects the way the
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.InlineModelAdmin.max_num" title="django.contrib.admin.InlineModelAdmin.max_num"><tt class="xref py py-attr docutils literal"><span class="pre">max_num</span></tt></a> argument is used for
inline admin objects.</p>
<p>Previously, the default value for <tt class="docutils literal"><span class="pre">max_num</span></tt> was <tt class="docutils literal"><span class="pre">0</span></tt> (zero).
FormSets then used the boolean value of <tt class="docutils literal"><span class="pre">max_num</span></tt> to determine if a
limit was to be imposed on the number of generated forms. The default
value of <tt class="docutils literal"><span class="pre">0</span></tt> meant that there was no default limit on the number of
forms in a FormSet.</p>
<p>Starting with 1.2, the default value for <tt class="docutils literal"><span class="pre">max_num</span></tt> has been changed
to <tt class="docutils literal"><span class="pre">None</span></tt>, and FormSets will differentiate between a value of
<tt class="docutils literal"><span class="pre">None</span></tt> and a value of <tt class="docutils literal"><span class="pre">0</span></tt>. A value of <tt class="docutils literal"><span class="pre">None</span></tt> indicates that no
limit on the number of forms is to be imposed; a value of <tt class="docutils literal"><span class="pre">0</span></tt>
indicates that a maximum of 0 forms should be imposed. This doesn&#8217;t
necessarily mean that no forms will be displayed &#8211; see the
<a class="reference internal" href="../topics/forms/modelforms.html#model-formsets-max-num"><em>ModelFormSet documentation</em></a> for more
details.</p>
<p>If you were manually specifying a value of <tt class="docutils literal"><span class="pre">0</span></tt> for <tt class="docutils literal"><span class="pre">max_num</span></tt>, you
will need to update your FormSet and/or admin definitions.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#js-assisted-inlines"><em>JavaScript-assisted handling of inline related objects in the admin</em></a></p>
</div>
</div>
<div class="section" id="s-email-re">
<span id="email-re"></span><h3><tt class="docutils literal"><span class="pre">email_re</span></tt><a class="headerlink" href="#email-re" title="Permalink to this headline">¶</a></h3>
<p>An undocumented regular expression for validating email addresses has been moved
from <tt class="docutils literal"><span class="pre">django.form.fields</span></tt> to <tt class="docutils literal"><span class="pre">django.core.validators</span></tt>. You will need to
update your imports if you are using it.</p>
</div>
</div>
<div class="section" id="s-features-deprecated-in-1-2">
<span id="s-deprecated-features-1-2"></span><span id="features-deprecated-in-1-2"></span><span id="deprecated-features-1-2"></span><h2>Features deprecated in 1.2<a class="headerlink" href="#features-deprecated-in-1-2" title="Permalink to this headline">¶</a></h2>
<p>Finally, Django 1.2 deprecates some features from earlier releases.
These features are still supported, but will be gradually phased out
over the next few release cycles.</p>
<p>Code taking advantage of any of the features below will raise a
<tt class="docutils literal"><span class="pre">PendingDeprecationWarning</span></tt> in Django 1.2. This warning will be
silent by default, but may be turned on using Python&#8217;s <a class="reference external" href="http://docs.python.org/3/library/warnings.html#module-warnings" title="(in Python v3.4)"><tt class="xref py py-mod docutils literal"><span class="pre">warnings</span></tt></a>
module, or by running Python with a <tt class="docutils literal"><span class="pre">-Wd</span></tt> or <tt class="docutils literal"><span class="pre">-Wall</span></tt> flag.</p>
<p>In Django 1.3, these warnings will become a <tt class="docutils literal"><span class="pre">DeprecationWarning</span></tt>,
which is <em>not</em> silent. In Django 1.4 support for these features will
be removed entirely.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">For more details, see the documentation <a class="reference internal" href="../internals/release-process.html"><em>Django&#8217;s release process</em></a> and our <a class="reference internal" href="../internals/deprecation.html"><em>deprecation timeline</em></a>.`</p>
</div>
<div class="section" id="s-specifying-databases">
<span id="s-id1"></span><span id="specifying-databases"></span><span id="id1"></span><h3>Specifying databases<a class="headerlink" href="#specifying-databases" title="Permalink to this headline">¶</a></h3>
<p>Prior to Django 1.2, Django used a number of settings to control
access to a single database. Django 1.2 introduces support for
multiple databases, and as a result the way you define database
settings has changed.</p>
<p>Any existing Django settings file will continue to work as expected
until Django 1.4. Until then, old-style database settings will be
automatically translated to the new-style format.</p>
<p>In the old-style (pre 1.2) format, you had a number of <tt class="docutils literal"><span class="pre">DATABASE_</span></tt>
settings in your settings file. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">DATABASE_NAME</span> <span class="o">=</span> <span class="s">&#39;test_db&#39;</span>
<span class="n">DATABASE_ENGINE</span> <span class="o">=</span> <span class="s">&#39;postgresql_psycopg2&#39;</span>
<span class="n">DATABASE_USER</span> <span class="o">=</span> <span class="s">&#39;myusername&#39;</span>
<span class="n">DATABASE_PASSWORD</span> <span class="o">=</span> <span class="s">&#39;s3krit&#39;</span>
</pre></div>
</div>
<p>These settings are now in a dictionary named
<a class="reference internal" href="../ref/settings.html#std:setting-DATABASES"><tt class="xref std std-setting docutils literal"><span class="pre">DATABASES</span></tt></a>. Each item in the dictionary corresponds to a
single database connection, with the name <tt class="docutils literal"><span class="pre">'default'</span></tt> describing the
default database connection. The setting names have also been
shortened. The previous sample settings would now look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s">&#39;NAME&#39;</span><span class="p">:</span> <span class="s">&#39;test_db&#39;</span><span class="p">,</span>
        <span class="s">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s">&#39;django.db.backends.postgresql_psycopg2&#39;</span><span class="p">,</span>
        <span class="s">&#39;USER&#39;</span><span class="p">:</span> <span class="s">&#39;myusername&#39;</span><span class="p">,</span>
        <span class="s">&#39;PASSWORD&#39;</span><span class="p">:</span> <span class="s">&#39;s3krit&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This affects the following settings:</p>
<table class="docutils">
<colgroup>
<col width="54%" />
<col width="46%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Old setting</th>
<th class="head">New Setting</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><cite>DATABASE_ENGINE</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-ENGINE"><tt class="xref std std-setting docutils literal"><span class="pre">ENGINE</span></tt></a></td>
</tr>
<tr class="row-odd"><td><cite>DATABASE_HOST</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-HOST"><tt class="xref std std-setting docutils literal"><span class="pre">HOST</span></tt></a></td>
</tr>
<tr class="row-even"><td><cite>DATABASE_NAME</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-NAME"><tt class="xref std std-setting docutils literal"><span class="pre">NAME</span></tt></a></td>
</tr>
<tr class="row-odd"><td><cite>DATABASE_OPTIONS</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-OPTIONS"><tt class="xref std std-setting docutils literal"><span class="pre">OPTIONS</span></tt></a></td>
</tr>
<tr class="row-even"><td><cite>DATABASE_PASSWORD</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD"><tt class="xref std std-setting docutils literal"><span class="pre">PASSWORD</span></tt></a></td>
</tr>
<tr class="row-odd"><td><cite>DATABASE_PORT</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-PORT"><tt class="xref std std-setting docutils literal"><span class="pre">PORT</span></tt></a></td>
</tr>
<tr class="row-even"><td><cite>DATABASE_USER</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-USER"><tt class="xref std std-setting docutils literal"><span class="pre">USER</span></tt></a></td>
</tr>
<tr class="row-odd"><td><cite>TEST_DATABASE_CHARSET</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-TEST_CHARSET"><tt class="xref std std-setting docutils literal"><span class="pre">TEST_CHARSET</span></tt></a></td>
</tr>
<tr class="row-even"><td><cite>TEST_DATABASE_COLLATION</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-TEST_COLLATION"><tt class="xref std std-setting docutils literal"><span class="pre">TEST_COLLATION</span></tt></a></td>
</tr>
<tr class="row-odd"><td><cite>TEST_DATABASE_NAME</cite></td>
<td><a class="reference internal" href="../ref/settings.html#std:setting-TEST_NAME"><tt class="xref std std-setting docutils literal"><span class="pre">TEST_NAME</span></tt></a></td>
</tr>
</tbody>
</table>
<p>These changes are also required if you have manually created a database
connection using <tt class="docutils literal"><span class="pre">DatabaseWrapper()</span></tt> from your database backend of choice.</p>
<p>In addition to the change in structure, Django 1.2 removes the special
handling for the built-in database backends. All database backends
must now be specified by a fully qualified module name (i.e.,
<tt class="docutils literal"><span class="pre">django.db.backends.postgresql_psycopg2</span></tt>, rather than just
<tt class="docutils literal"><span class="pre">postgresql_psycopg2</span></tt>).</p>
</div>
<div class="section" id="s-postgresql-database-backend">
<span id="postgresql-database-backend"></span><h3><tt class="docutils literal"><span class="pre">postgresql</span></tt> database backend<a class="headerlink" href="#postgresql-database-backend" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">psycopg1</span></tt> library has not been updated since October 2005. As a
result, the <tt class="docutils literal"><span class="pre">postgresql</span></tt> database backend, which uses this library,
has been deprecated.</p>
<p>If you are currently using the <tt class="docutils literal"><span class="pre">postgresql</span></tt> backend, you should
migrate to using the <tt class="docutils literal"><span class="pre">postgresql_psycopg2</span></tt> backend. To update your
code, install the <tt class="docutils literal"><span class="pre">psycopg2</span></tt> library and change the
<a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-ENGINE"><tt class="xref std std-setting docutils literal"><span class="pre">ENGINE</span></tt></a> setting to use
<tt class="docutils literal"><span class="pre">django.db.backends.postgresql_psycopg2</span></tt>.</p>
</div>
<div class="section" id="s-csrf-response-rewriting-middleware">
<span id="csrf-response-rewriting-middleware"></span><h3>CSRF response-rewriting middleware<a class="headerlink" href="#csrf-response-rewriting-middleware" title="Permalink to this headline">¶</a></h3>
<p><tt class="docutils literal"><span class="pre">CsrfResponseMiddleware</span></tt>, the middleware that automatically inserted
CSRF tokens into <tt class="docutils literal"><span class="pre">POST</span></tt> forms in outgoing pages, has been deprecated
in favor of a template tag method (see above), and will be removed
completely in Django 1.4. <tt class="docutils literal"><span class="pre">CsrfMiddleware</span></tt>, which includes the
functionality of <tt class="docutils literal"><span class="pre">CsrfResponseMiddleware</span></tt> and
<tt class="docutils literal"><span class="pre">CsrfViewMiddleware</span></tt>, has likewise been deprecated.</p>
<p>Also, the CSRF module has moved from contrib to core, and the old
imports are deprecated, as described in the upgrading notes.</p>
<div class="admonition-documentation-removed admonition">
<p class="first admonition-title">Documentation removed</p>
<p class="last">The upgrade notes have been removed in current Django docs. Please refer
to the docs for Django 1.3 or older to find these instructions.</p>
</div>
</div>
<div class="section" id="s-smtpconnection">
<span id="smtpconnection"></span><h3><tt class="docutils literal"><span class="pre">SMTPConnection</span></tt><a class="headerlink" href="#smtpconnection" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">SMTPConnection</span></tt> class has been deprecated in favor of a generic
email backend API. Old code that explicitly instantiated an instance
of an SMTPConnection:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.core.mail</span> <span class="kn">import</span> <span class="n">SMTPConnection</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">SMTPConnection</span><span class="p">()</span>
<span class="n">messages</span> <span class="o">=</span> <span class="n">get_notification_email</span><span class="p">()</span>
<span class="n">connection</span><span class="o">.</span><span class="n">send_messages</span><span class="p">(</span><span class="n">messages</span><span class="p">)</span>
</pre></div>
</div>
<p>...should now call <a class="reference internal" href="../topics/email.html#django.core.mail.get_connection" title="django.core.mail.get_connection"><tt class="xref py py-meth docutils literal"><span class="pre">get_connection()</span></tt></a> to
instantiate a generic email connection:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.core.mail</span> <span class="kn">import</span> <span class="n">get_connection</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">get_connection</span><span class="p">()</span>
<span class="n">messages</span> <span class="o">=</span> <span class="n">get_notification_email</span><span class="p">()</span>
<span class="n">connection</span><span class="o">.</span><span class="n">send_messages</span><span class="p">(</span><span class="n">messages</span><span class="p">)</span>
</pre></div>
</div>
<p>Depending on the value of the <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_BACKEND"><tt class="xref std std-setting docutils literal"><span class="pre">EMAIL_BACKEND</span></tt></a> setting, this
may not return an SMTP connection. If you explicitly require an SMTP
connection with which to send email, you can explicitly request an
SMTP connection:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.core.mail</span> <span class="kn">import</span> <span class="n">get_connection</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">get_connection</span><span class="p">(</span><span class="s">&#39;django.core.mail.backends.smtp.EmailBackend&#39;</span><span class="p">)</span>
<span class="n">messages</span> <span class="o">=</span> <span class="n">get_notification_email</span><span class="p">()</span>
<span class="n">connection</span><span class="o">.</span><span class="n">send_messages</span><span class="p">(</span><span class="n">messages</span><span class="p">)</span>
</pre></div>
</div>
<p>If your call to construct an instance of <tt class="docutils literal"><span class="pre">SMTPConnection</span></tt> required
additional arguments, those arguments can be passed to the
<a class="reference internal" href="../topics/email.html#django.core.mail.get_connection" title="django.core.mail.get_connection"><tt class="xref py py-meth docutils literal"><span class="pre">get_connection()</span></tt></a> call:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">connection</span> <span class="o">=</span> <span class="n">get_connection</span><span class="p">(</span><span class="s">&#39;django.core.mail.backends.smtp.EmailBackend&#39;</span><span class="p">,</span> <span class="n">hostname</span><span class="o">=</span><span class="s">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">1234</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-user-messages-api">
<span id="user-messages-api"></span><h3>User Messages API<a class="headerlink" href="#user-messages-api" title="Permalink to this headline">¶</a></h3>
<p>The API for storing messages in the user <tt class="docutils literal"><span class="pre">Message</span></tt> model (via
<tt class="docutils literal"><span class="pre">user.message_set.create</span></tt>) is now deprecated and will be removed in Django
1.4 according to the standard <a class="reference internal" href="../internals/release-process.html"><em>release process</em></a>.</p>
<p>To upgrade your code, you need to replace any instances of this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">user</span><span class="o">.</span><span class="n">message_set</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="s">&#39;a message&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>...with the following:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">messages</span>
<span class="n">messages</span><span class="o">.</span><span class="n">add_message</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">INFO</span><span class="p">,</span> <span class="s">&#39;a message&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Additionally, if you make use of the method, you need to replace the
following:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">user</span><span class="o">.</span><span class="n">get_and_delete_messages</span><span class="p">():</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>...with:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">messages</span>
<span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">messages</span><span class="o">.</span><span class="n">get_messages</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>For more information, see the full
<a class="reference internal" href="../ref/contrib/messages.html"><em>messages documentation</em></a>. You should begin to
update your code to use the new API immediately.</p>
</div>
<div class="section" id="s-date-format-helper-functions">
<span id="date-format-helper-functions"></span><h3>Date format helper functions<a class="headerlink" href="#date-format-helper-functions" title="Permalink to this headline">¶</a></h3>
<p><tt class="docutils literal"><span class="pre">django.utils.translation.get_date_formats()</span></tt> and
<tt class="docutils literal"><span class="pre">django.utils.translation.get_partial_date_formats()</span></tt> have been deprecated
in favor of the appropriate calls to <tt class="docutils literal"><span class="pre">django.utils.formats.get_format()</span></tt>,
which is locale-aware when <a class="reference internal" href="../ref/settings.html#std:setting-USE_L10N"><tt class="xref std std-setting docutils literal"><span class="pre">USE_L10N</span></tt></a> is set to <tt class="docutils literal"><span class="pre">True</span></tt>, and falls
back to default settings if set to <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>To get the different date formats, instead of writing this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">get_date_formats</span>
<span class="n">date_format</span><span class="p">,</span> <span class="n">datetime_format</span><span class="p">,</span> <span class="n">time_format</span> <span class="o">=</span> <span class="n">get_date_formats</span><span class="p">()</span>
</pre></div>
</div>
<p>...use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">formats</span>
<span class="n">date_format</span> <span class="o">=</span> <span class="n">formats</span><span class="o">.</span><span class="n">get_format</span><span class="p">(</span><span class="s">&#39;DATE_FORMAT&#39;</span><span class="p">)</span>
<span class="n">datetime_format</span> <span class="o">=</span> <span class="n">formats</span><span class="o">.</span><span class="n">get_format</span><span class="p">(</span><span class="s">&#39;DATETIME_FORMAT&#39;</span><span class="p">)</span>
<span class="n">time_format</span> <span class="o">=</span> <span class="n">formats</span><span class="o">.</span><span class="n">get_format</span><span class="p">(</span><span class="s">&#39;TIME_FORMAT&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Or, when directly formatting a date value:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">formats</span>
<span class="n">value_formatted</span> <span class="o">=</span> <span class="n">formats</span><span class="o">.</span><span class="n">date_format</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s">&#39;DATETIME_FORMAT&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The same applies to the globals found in <tt class="docutils literal"><span class="pre">django.forms.fields</span></tt>:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">DEFAULT_DATE_INPUT_FORMATS</span></tt></li>
<li><tt class="docutils literal"><span class="pre">DEFAULT_TIME_INPUT_FORMATS</span></tt></li>
<li><tt class="docutils literal"><span class="pre">DEFAULT_DATETIME_INPUT_FORMATS</span></tt></li>
</ul>
<p>Use <tt class="docutils literal"><span class="pre">django.utils.formats.get_format()</span></tt> to get the appropriate formats.</p>
</div>
<div class="section" id="s-function-based-test-runners">
<span id="function-based-test-runners"></span><h3>Function-based test runners<a class="headerlink" href="#function-based-test-runners" title="Permalink to this headline">¶</a></h3>
<p>Django 1.2 changes the test runner tools to use a class-based
approach. Old style function-based test runners will still work, but
should be updated to use the new <a class="reference internal" href="../topics/testing/advanced.html#topics-testing-test-runner"><em>class-based runners</em></a>.</p>
</div>
<div class="section" id="s-feed-in-django-contrib-syndication-feeds">
<span id="s-updating-feeds"></span><span id="feed-in-django-contrib-syndication-feeds"></span><span id="updating-feeds"></span><h3><tt class="docutils literal"><span class="pre">Feed</span></tt> in <tt class="docutils literal"><span class="pre">django.contrib.syndication.feeds</span></tt><a class="headerlink" href="#feed-in-django-contrib-syndication-feeds" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">django.contrib.syndication.feeds.Feed</span></tt> class has been
replaced by the <a class="reference internal" href="../ref/contrib/syndication.html#django.contrib.syndication.views.Feed" title="django.contrib.syndication.views.Feed"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.syndication.views.Feed</span></tt></a> class.
The old <tt class="docutils literal"><span class="pre">feeds.Feed</span></tt> class is deprecated, and will be removed in
Django 1.4.</p>
<p>The new class has an almost identical API, but allows instances to be
used as views. For example, consider the use of the old framework in
the following <a class="reference internal" href="../topics/http/urls.html"><em>URLconf</em></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">myproject.feeds</span> <span class="kn">import</span> <span class="n">LatestEntries</span><span class="p">,</span> <span class="n">LatestEntriesByCategory</span>

<span class="n">feeds</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;latest&#39;</span><span class="p">:</span> <span class="n">LatestEntries</span><span class="p">,</span>
    <span class="s">&#39;categories&#39;</span><span class="p">:</span> <span class="n">LatestEntriesByCategory</span><span class="p">,</span>
<span class="p">}</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="c"># ...</span>
    <span class="p">(</span><span class="s">r&#39;^feeds/(?P&lt;url&gt;.*)/$&#39;</span><span class="p">,</span> <span class="s">&#39;django.contrib.syndication.views.feed&#39;</span><span class="p">,</span>
        <span class="p">{</span><span class="s">&#39;feed_dict&#39;</span><span class="p">:</span> <span class="n">feeds</span><span class="p">}),</span>
    <span class="c"># ...</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Using the new Feed class, these feeds can be deployed directly as views:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">myproject.feeds</span> <span class="kn">import</span> <span class="n">LatestEntries</span><span class="p">,</span> <span class="n">LatestEntriesByCategory</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="c"># ...</span>
    <span class="p">(</span><span class="s">r&#39;^feeds/latest/$&#39;</span><span class="p">,</span> <span class="n">LatestEntries</span><span class="p">()),</span>
    <span class="p">(</span><span class="s">r&#39;^feeds/categories/(?P&lt;category_id&gt;\d+)/$&#39;</span><span class="p">,</span> <span class="n">LatestEntriesByCategory</span><span class="p">()),</span>
    <span class="c"># ...</span>
<span class="p">)</span>
</pre></div>
</div>
<p>If you currently use the <tt class="docutils literal"><span class="pre">feed()</span></tt> view, the <tt class="docutils literal"><span class="pre">LatestEntries</span></tt> class would
often not need to be modified apart from subclassing the new
<a class="reference internal" href="../ref/contrib/syndication.html#django.contrib.syndication.views.Feed" title="django.contrib.syndication.views.Feed"><tt class="xref py py-class docutils literal"><span class="pre">Feed</span></tt></a> class. The exception is if
Django was automatically working out the name of the template to use to render
the feed&#8217;s description and title elements (if you were not specifying the
<tt class="docutils literal"><span class="pre">title_template</span></tt> and <tt class="docutils literal"><span class="pre">description_template</span></tt> attributes). You should ensure
that you always specify <tt class="docutils literal"><span class="pre">title_template</span></tt> and <tt class="docutils literal"><span class="pre">description_template</span></tt>
attributes, or provide <tt class="docutils literal"><span class="pre">item_title()</span></tt> and <tt class="docutils literal"><span class="pre">item_description()</span></tt> methods.</p>
<p>However, <tt class="docutils literal"><span class="pre">LatestEntriesByCategory</span></tt> uses the <tt class="docutils literal"><span class="pre">get_object()</span></tt> method
with the <tt class="docutils literal"><span class="pre">bits</span></tt> argument to specify a specific category to show. In
the new <a class="reference internal" href="../ref/contrib/syndication.html#django.contrib.syndication.views.Feed" title="django.contrib.syndication.views.Feed"><tt class="xref py py-class docutils literal"><span class="pre">Feed</span></tt></a> class,
<tt class="docutils literal"><span class="pre">get_object()</span></tt> method takes a <tt class="docutils literal"><span class="pre">request</span></tt> and arguments from the
URL, so it would look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.syndication.views</span> <span class="kn">import</span> <span class="n">Feed</span>
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">get_object_or_404</span>
<span class="kn">from</span> <span class="nn">myproject.models</span> <span class="kn">import</span> <span class="n">Category</span>

<span class="k">class</span> <span class="nc">LatestEntriesByCategory</span><span class="p">(</span><span class="n">Feed</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">category_id</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Category</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="n">category_id</span><span class="p">)</span>

    <span class="c"># ...</span>
</pre></div>
</div>
<p>Additionally, the <tt class="docutils literal"><span class="pre">get_feed()</span></tt> method on <tt class="docutils literal"><span class="pre">Feed</span></tt> classes now take
different arguments, which may impact you if you use the <tt class="docutils literal"><span class="pre">Feed</span></tt>
classes directly. Instead of just taking an optional <tt class="docutils literal"><span class="pre">url</span></tt> argument,
it now takes two arguments: the object returned by its own
<tt class="docutils literal"><span class="pre">get_object()</span></tt> method, and the current <tt class="docutils literal"><span class="pre">request</span></tt> object.</p>
<p>To take into account <tt class="docutils literal"><span class="pre">Feed</span></tt> classes not being initialized for each
request, the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method now takes no arguments by default.
Previously it would have taken the <tt class="docutils literal"><span class="pre">slug</span></tt> from the URL and the
<tt class="docutils literal"><span class="pre">request</span></tt> object.</p>
<p>In accordance with <a class="reference external" href="http://www.rssboard.org/rss-profile">RSS best practices</a>, RSS feeds will now include
an <tt class="docutils literal"><span class="pre">atom:link</span></tt> element. You may need to update your tests to take
this into account.</p>
<p>For more information, see the full <a class="reference internal" href="../ref/contrib/syndication.html"><em>syndication framework
documentation</em></a>.</p>
</div>
<div class="section" id="s-technical-message-ids">
<span id="technical-message-ids"></span><h3>Technical message IDs<a class="headerlink" href="#technical-message-ids" title="Permalink to this headline">¶</a></h3>
<p>Up to version 1.1 Django used technical message IDs
to provide localizers the possibility to translate date and time formats. They
were translatable <a class="reference internal" href="../topics/i18n/index.html#term-translation-string"><em class="xref std std-term">translation strings</em></a> that could
be recognized because they were all upper case (for example
<a class="reference internal" href="../ref/settings.html#std:setting-DATETIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATETIME_FORMAT</span></tt></a>, <a class="reference internal" href="../ref/settings.html#std:setting-DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_FORMAT</span></tt></a>, <a class="reference internal" href="../ref/settings.html#std:setting-TIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">TIME_FORMAT</span></tt></a>).
They have been deprecated in favor of the new <a class="reference internal" href="../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a> infrastructure that allows localizers to specify that
information in a <tt class="docutils literal"><span class="pre">formats.py</span></tt> file in the corresponding
<tt class="docutils literal"><span class="pre">django/conf/locale/&lt;locale</span> <span class="pre">name&gt;/</span></tt> directory.</p>
</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3>GeoDjango<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>To allow support for multiple databases, the GeoDjango database internals were
changed substantially.  The largest backwards-incompatible change is that
the module <tt class="docutils literal"><span class="pre">django.contrib.gis.db.backend</span></tt> was renamed to
<a class="reference internal" href="../ref/contrib/gis/db-api.html#module-django.contrib.gis.db.backends" title="django.contrib.gis.db.backends: GeoDjango's spatial database backends."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.gis.db.backends</span></tt></a>, where the full-fledged
<a class="reference internal" href="../ref/contrib/gis/db-api.html#spatial-backends"><em>spatial database backends</em></a> now exist.  The
following sections provide information on the most-popular APIs that
were affected by these changes.</p>
<div class="section" id="s-spatialbackend">
<span id="spatialbackend"></span><h4><tt class="docutils literal"><span class="pre">SpatialBackend</span></tt><a class="headerlink" href="#spatialbackend" title="Permalink to this headline">¶</a></h4>
<p>Prior to the creation of the separate spatial backends, the
<tt class="docutils literal"><span class="pre">django.contrib.gis.db.backend.SpatialBackend</span></tt> object was
provided as an abstraction to introspect on the capabilities of
the spatial database.  All of the attributes and routines provided by
<tt class="docutils literal"><span class="pre">SpatialBackend</span></tt> are now a part of the <tt class="docutils literal"><span class="pre">ops</span></tt> attribute of the
database backend.</p>
<p>The old module <tt class="docutils literal"><span class="pre">django.contrib.gis.db.backend</span></tt> is still provided
for backwards-compatibility access to a <tt class="docutils literal"><span class="pre">SpatialBackend</span></tt> object,
which is just an alias to the <tt class="docutils literal"><span class="pre">ops</span></tt> module of the
<em>default</em> spatial database connection.</p>
<p>Users that were relying on undocumented modules and objects
within <tt class="docutils literal"><span class="pre">django.contrib.gis.db.backend</span></tt>, rather the abstractions
provided by <tt class="docutils literal"><span class="pre">SpatialBackend</span></tt>, are required to modify their code.
For example, the following import which would work in 1.1 and
below:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.gis.db.backend.postgis</span> <span class="kn">import</span> <span class="n">PostGISAdaptor</span>
</pre></div>
</div>
<p>Would need to be changed:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">connection</span>
<span class="n">PostGISAdaptor</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">Adapter</span>
</pre></div>
</div>
</div>
<div class="section" id="s-spatialrefsys-and-geometrycolumns-models">
<span id="spatialrefsys-and-geometrycolumns-models"></span><h4><tt class="docutils literal"><span class="pre">SpatialRefSys</span></tt> and <tt class="docutils literal"><span class="pre">GeometryColumns</span></tt> models<a class="headerlink" href="#spatialrefsys-and-geometrycolumns-models" title="Permalink to this headline">¶</a></h4>
<p>In previous versions of GeoDjango, <a class="reference internal" href="../ref/contrib/gis/model-api.html#module-django.contrib.gis.db.models" title="django.contrib.gis.db.models: GeoDjango model and field API."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.gis.db.models</span></tt></a>
had <tt class="docutils literal"><span class="pre">SpatialRefSys</span></tt> and <tt class="docutils literal"><span class="pre">GeometryColumns</span></tt> models for querying
the OGC spatial metadata tables <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> and <tt class="docutils literal"><span class="pre">geometry_columns</span></tt>,
respectively.</p>
<p>While these aliases are still provided, they are only for the
<em>default</em> database connection and exist only if the default connection
is using a supported spatial database backend.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Because the table structure of the OGC spatial metadata tables
differs across spatial databases, the <tt class="docutils literal"><span class="pre">SpatialRefSys</span></tt> and
<tt class="docutils literal"><span class="pre">GeometryColumns</span></tt> models can no longer be associated with
the <tt class="docutils literal"><span class="pre">gis</span></tt> application name.  Thus, no models will be returned
when using the <tt class="docutils literal"><span class="pre">get_models</span></tt> method in the following example:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">get_app</span><span class="p">,</span> <span class="n">get_models</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_models</span><span class="p">(</span><span class="n">get_app</span><span class="p">(</span><span class="s">&#39;gis&#39;</span><span class="p">))</span>
<span class="go">[]</span>
</pre></div>
</div>
</div>
<p>To get the correct <tt class="docutils literal"><span class="pre">SpatialRefSys</span></tt> and <tt class="docutils literal"><span class="pre">GeometryColumns</span></tt>
for your spatial database use the methods provided by the spatial backend:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">connections</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SpatialRefSys</span> <span class="o">=</span> <span class="n">connections</span><span class="p">[</span><span class="s">&#39;my_spatialite&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">spatial_ref_sys</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GeometryColumns</span> <span class="o">=</span> <span class="n">connections</span><span class="p">[</span><span class="s">&#39;my_postgis&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">geometry_columns</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>When using the models returned from the <tt class="docutils literal"><span class="pre">spatial_ref_sys()</span></tt> and
<tt class="docutils literal"><span class="pre">geometry_columns()</span></tt> method, you&#8217;ll still need to use the
correct database alias when querying on the non-default connection.
In other words, to ensure that the models in the example above
use the correct database:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">sr_qs</span> <span class="o">=</span> <span class="n">SpatialRefSys</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="s">&#39;my_spatialite&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="n">gc_qs</span> <span class="o">=</span> <span class="n">GeometryColumns</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="s">&#39;my_postgis&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="s-language-code-no">
<span id="language-code-no"></span><h3>Language code <tt class="docutils literal"><span class="pre">no</span></tt><a class="headerlink" href="#language-code-no" title="Permalink to this headline">¶</a></h3>
<p>The currently used language code for Norwegian Bokmål <tt class="docutils literal"><span class="pre">no</span></tt> is being
replaced by the more common language code <tt class="docutils literal"><span class="pre">nb</span></tt>.</p>
</div>
<div class="section" id="s-function-based-template-loaders">
<span id="function-based-template-loaders"></span><h3>Function-based template loaders<a class="headerlink" href="#function-based-template-loaders" title="Permalink to this headline">¶</a></h3>
<p>Django 1.2 changes the template loading mechanism to use a class-based
approach. Old style function-based template loaders will still work, but should
be updated to use the new <a class="reference internal" href="../ref/templates/api.html#topic-template-alternate-language"><em>class-based template loaders</em></a>.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django 1.2 release notes</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#python-compatibility">Python compatibility</a></li>
<li><a class="reference internal" href="#what-s-new-in-django-1-2">What&#8217;s new in Django 1.2</a><ul>
<li><a class="reference internal" href="#support-for-multiple-databases">Support for multiple databases</a></li>
<li><a class="reference internal" href="#model-validation">Model validation</a></li>
<li><a class="reference internal" href="#improved-csrf-protection">Improved CSRF protection</a></li>
<li><a class="reference internal" href="#messages-framework">Messages framework</a></li>
<li><a class="reference internal" href="#object-level-permissions">Object-level permissions</a></li>
<li><a class="reference internal" href="#permissions-for-anonymous-users">Permissions for anonymous users</a></li>
<li><a class="reference internal" href="#relaxed-requirements-for-usernames">Relaxed requirements for usernames</a></li>
<li><a class="reference internal" href="#email-backends">Email backends</a></li>
<li><a class="reference internal" href="#smart-if-tag">&#8220;Smart&#8221; <tt class="docutils literal"><span class="pre">if</span></tt> tag</a></li>
<li><a class="reference internal" href="#template-caching">Template caching</a></li>
<li><a class="reference internal" href="#class-based-template-loaders">Class-based template loaders</a></li>
<li><a class="reference internal" href="#natural-keys-in-fixtures">Natural keys in fixtures</a></li>
<li><a class="reference internal" href="#fast-failure-for-tests">Fast failure for tests</a></li>
<li><a class="reference internal" href="#bigintegerfield"><tt class="docutils literal"><span class="pre">BigIntegerField</span></tt></a></li>
<li><a class="reference internal" href="#improved-localization">Improved localization</a></li>
<li><a class="reference internal" href="#readonly-fields-in-modeladmin"><tt class="docutils literal"><span class="pre">readonly_fields</span></tt> in <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt></a></li>
<li><a class="reference internal" href="#customizable-syntax-highlighting">Customizable syntax highlighting</a></li>
<li><a class="reference internal" href="#syndication-feeds-as-views">Syndication feeds as views</a></li>
<li><a class="reference internal" href="#geodjango">GeoDjango</a></li>
<li><a class="reference internal" href="#javascript-assisted-handling-of-inline-related-objects-in-the-admin">JavaScript-assisted handling of inline related objects in the admin</a></li>
<li><a class="reference internal" href="#new-now-template-tag-format-specifier-characters-c-and-u">New <tt class="docutils literal"><span class="pre">now</span></tt> template tag format specifier characters: <tt class="docutils literal"><span class="pre">c</span></tt> and <tt class="docutils literal"><span class="pre">u</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#backwards-incompatible-changes-in-1-2">Backwards-incompatible changes in 1.2</a><ul>
<li><a class="reference internal" href="#csrf-protection">CSRF Protection</a></li>
<li><a class="reference internal" href="#get-db-prep-methods-on-field"><tt class="docutils literal"><span class="pre">get_db_prep_*()</span></tt> methods on <tt class="docutils literal"><span class="pre">Field</span></tt></a></li>
<li><a class="reference internal" href="#stateful-template-tags">Stateful template tags</a></li>
<li><a class="reference internal" href="#user-passes-test-login-required-and-permission-required"><tt class="docutils literal"><span class="pre">user_passes_test</span></tt>, <tt class="docutils literal"><span class="pre">login_required</span></tt> and <tt class="docutils literal"><span class="pre">permission_required</span></tt></a></li>
<li><a class="reference internal" href="#if-tag-changes"><tt class="docutils literal"><span class="pre">if</span></tt> tag changes</a></li>
<li><a class="reference internal" href="#lazyobject"><tt class="docutils literal"><span class="pre">LazyObject</span></tt></a></li>
<li><a class="reference internal" href="#dict-on-model-instances"><tt class="docutils literal"><span class="pre">__dict__</span></tt> on model instances</a></li>
<li><a class="reference internal" href="#test-runner-exit-status-code">Test runner exit status code</a></li>
<li><a class="reference internal" href="#cookie-encoding">Cookie encoding</a></li>
<li><a class="reference internal" href="#modelform-is-valid-and-modelform-errors"><tt class="docutils literal"><span class="pre">ModelForm.is_valid()</span></tt> and <tt class="docutils literal"><span class="pre">ModelForm.errors</span></tt></a></li>
<li><a class="reference internal" href="#booleanfield-on-mysql"><tt class="docutils literal"><span class="pre">BooleanField</span></tt> on MySQL</a></li>
<li><a class="reference internal" href="#changes-to-the-interpretation-of-max-num-in-formsets">Changes to the interpretation of <tt class="docutils literal"><span class="pre">max_num</span></tt> in FormSets</a></li>
<li><a class="reference internal" href="#email-re"><tt class="docutils literal"><span class="pre">email_re</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-deprecated-in-1-2">Features deprecated in 1.2</a><ul>
<li><a class="reference internal" href="#specifying-databases">Specifying databases</a></li>
<li><a class="reference internal" href="#postgresql-database-backend"><tt class="docutils literal"><span class="pre">postgresql</span></tt> database backend</a></li>
<li><a class="reference internal" href="#csrf-response-rewriting-middleware">CSRF response-rewriting middleware</a></li>
<li><a class="reference internal" href="#smtpconnection"><tt class="docutils literal"><span class="pre">SMTPConnection</span></tt></a></li>
<li><a class="reference internal" href="#user-messages-api">User Messages API</a></li>
<li><a class="reference internal" href="#date-format-helper-functions">Date format helper functions</a></li>
<li><a class="reference internal" href="#function-based-test-runners">Function-based test runners</a></li>
<li><a class="reference internal" href="#feed-in-django-contrib-syndication-feeds"><tt class="docutils literal"><span class="pre">Feed</span></tt> in <tt class="docutils literal"><span class="pre">django.contrib.syndication.feeds</span></tt></a></li>
<li><a class="reference internal" href="#technical-message-ids">Technical message IDs</a></li>
<li><a class="reference internal" href="#id2">GeoDjango</a><ul>
<li><a class="reference internal" href="#spatialbackend"><tt class="docutils literal"><span class="pre">SpatialBackend</span></tt></a></li>
<li><a class="reference internal" href="#spatialrefsys-and-geometrycolumns-models"><tt class="docutils literal"><span class="pre">SpatialRefSys</span></tt> and <tt class="docutils literal"><span class="pre">GeometryColumns</span></tt> models</a></li>
</ul>
</li>
<li><a class="reference internal" href="#language-code-no">Language code <tt class="docutils literal"><span class="pre">no</span></tt></a></li>
<li><a class="reference internal" href="#function-based-template-loaders">Function-based template loaders</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="1.2.1.html">Django 1.2.1 release notes</a></li>
    
    
      <li>Next: <a href="1.1.4.html">Django 1.1.4 release notes</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="index.html">Release notes</a>
        
        <ul><li>Django 1.2 release notes</li></ul>
        </li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/releases/1.2.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="1.2.1.html" title="Django 1.2.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="1.1.4.html" title="Django 1.1.4 release notes">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>